﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace T5._3_admie
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlDataReader reader = null;
            
            //获取用户名和密码
            string Name = null;
            string Psw = null;

            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("用户名和密码不能为空");
            }else
            {
    
                try {

                        string sql =
                            //string.Format("select *from Customer Name='{0}' and Psw='{1}' )",textBox1.Text,textBox2.Text);
                            "select*from Customer where Name='" + textBox1.Text + "' and Paw='" + textBox2.Text + "'";
                        reader = sqlCommom.Select(sql);
                        while (reader.Read())
                        {
                            Name = reader["Name"].ToString();
                            Psw = reader["Paw"].ToString();
                        }
                        reader.Close();
                    }
                catch (Exception ex)
                {
                    MessageBox.Show("不明原因报错，请找管理员\n" + ex.Message);
                }
                if (Name == textBox1.Text && Psw == textBox2.Text)
                {
                    MessageBox.Show("登陆成功");
                }

                else
                {
                    MessageBox.Show("登陆失败");
                }
            }
            }
        }

      
    }

